package com.guo.springboot.config;

import org.springframework.core.annotation.Order;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Auther: hotlove_linx
 * @Date: 2021/8/6 00:59
 * @Description:
 */
@WebFilter(urlPatterns = "/profile/*", filterName = "commonFilter")
@Order(1)
public class CommonFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        long start = System.currentTimeMillis();
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        request.setCharacterEncoding("utf-8");

        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setContentType("text/json;charset=UTF-8");

        filterChain.doFilter(servletRequest, servletResponse);
        System.out.println("好视i"+(System.currentTimeMillis() - start));
    }

    @Override
    public void destroy() {
        Filter.super.destroy();
    }
}
